<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
  /**
   * Insert validation rules.
   *
   * @var array
   */
  public static $insertRules = [
    'slug' => 'required|max:255|unique:roles',
    'name' => 'required|max:255',
  ];

  /**
   * Update validation rules.
   *
   * @var array
   */
  public static $updatetRules = [
    'slug' => 'nullable|max:255|unique:roles',
    'name' => 'nullable|max:255',
  ];

  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = [
    'slug',
    'name',
    'active',
  ];

  /**
   * The attributes that should be cast to native types.
   *
   * @var array
   */
  protected $casts = [];

  /**
   * Relationship with users.
   */
  public function users()
  {
    return $this->hasMany(User::class);
  }

  /**
   * Relationship with permissions.
   */
  public function permissions()
  {
    return $this->belongsToMany(Permission::class, 'roles_permissions');
  }
}
